#{extends 'main.html' /}
<br/>
<head>
    <link rel="stylesheet" href="/public/stylesheets/demo_table.css">
    <script type="text/javascript" language="javascript" src="/public/javascripts/jquery.js">
    </script>
    <script type="text/javascript" language="javascript" src="/public/javascripts/jquery.dataTables.js">
    </script>
    <script type="text/javascript" charset="utf-8">
        var oTable;
        var asInitVals = new Array();
        
        $(document).ready(function(){
            oTable = $('#table').dataTable({
                "oLanguage": {
                    "sSearch": "Search all columns:"
                }
            });
            
            $("tfoot input").keyup(function(){
                /* Filter on the column (the index) of this element */
                oTable.fnFilter(this.value, $("tfoot input").index(this));
            });
            
            
            
            /*
             * Support functions to provide a little bit of 'user friendlyness' to the textboxes in
             * the footer
             */
            $("tfoot input").each(function(i){
                asInitVals[i] = this.value;
            });
            
            $("tfoot input").focus(function(){
                if (this.className == "search_init") {
                    this.className = "";
                    this.value = "";
                }
            });
            
            $("tfoot input").blur(function(i){
                if (this.value == "") {
                    this.className = "search_init";
                    this.value = asInitVals[$("tfoot input").index(this)];
                }
            });
        });
    </script>
</head>
<body id="dt_example">
    <h2>
    <h2><a style ="color:#400040;" href = "@{Projects.showProject((Long)project.getEntityId())}">${project.name}</a> > Tasks</h2><hr/>
	<a href="@{Tasks.showSuggestDeveloperToTask(project.getEntityId())}">Suggest Task Assignee</a>
    &nbsp;&nbsp;|&nbsp;&nbsp;<a href="@{Tasks.mySuggestedTasks()}">My Suggested Tasks</a>
    #{secure.check 'Create/Edit/delete task type in my project'}&nbsp;&nbsp;|&nbsp;&nbsp;<a href="@{TaskTypes.index(project.getEntityId())}">Task Types/Statuses</a>
    #{/secure.check}
    #{secure.check 'assign a developer to a task'}&nbsp;&nbsp;|&nbsp;&nbsp;<a href="@{Tasks.assignDeveloperToTask(project.getEntityId())}">Assign Developer To Task</a>
    #{/secure.check} 
    <hr/> %{ 
    if(controllers.Security.checkPermission("approve requests by developers to be reviewers",project)) 
    {
    }%&nbsp;&nbsp;|&nbsp;&nbsp;<a href="@{Tasks.showTaskReviewRequests(project.getEntityId())}">View Review Requests</a>
    %{ 
    } else {  
    if(controllers.Security.checkPermission("approve task type review requests",project)) { 
    }%&nbsp;&nbsp;|&nbsp;&nbsp;<a href="@{Tasks.showTaskReviewRequests(project.getEntityId())}">View Review Requests</a>
    %{
    }
    }
    }%
    #{secure.check 'review a task'}
    &nbsp;&nbsp;|&nbsp;&nbsp;<a href="@{TaskTypes.showRequestReview(project.getEntityId())}">Request To Review Task Type</a>
    #{/secure.check}
	<hr/>
	#{secure.check 'Create/edit/delete Task in my project'}<a href="@{Tasks.showCreateTask(project.getEntityId())}">+ Add New Task </a>
    #{/secure.check}
    <br/>
    <br/>
    #{if projectTasks}
    <table cellpadding="0" cellspacing="0" border="0" class="display" id="table">
        <thead>
            <tr>
                <th>
                    Task
                </th>
                <th>
                    Type
                </th>
                <th>
                    Status
                </th>
                <th>
                    Priority
                </th>
                <th>
                    Creator
                </th>
                <th>
                    Assignee
                </th>
                <th>
                    Reviewer
                </th>
            </tr>
        </thead>
        <tbody>
            #{list items:projectTasks, as:'projectTask'}
            <tr>
                <td>
                    #{secure.check 'Create/edit/delete Task in my project'}<a href="javascript:showDialogHelper('Confirmation','Are you sure you want to delete?',true,'@{Tasks.deleteTask(projectTask.getEntityId(),project.getEntityId())}','prompt');"class = "link" style='COLOR:#ff0000' title="delete task?">x</a>
                    #{/secure.check}
                    &nbsp;&nbsp;&nbsp;<a href="@{Tasks.showTask(projectTask.getEntityId())}">${projectTask.description}</a>
                </td>
                <td>
                    #{if projectTask.type!=null}${projectTask.type.type}#{/if}
                </td>
                <td>
                    #{if projectTask.status!=null}${projectTask.status.status}#{/if}
                </td>
                <td>
                    #{if projectTask.priority!=null}${projectTask.priority}#{/if}
                </td>
                <td>
                    #{if projectTask.creator!=null}${projectTask.creator.firstName} ${projectTask.creator.lastName}#{/if}
                </td>
                <td>
                    %{ 
                    assignee = controllers.Tasks.renderGetTaskAssignee(projectTask.getEntityId());  
                    if (assignee != null) 
                    {  
                    firstName = assignee.firstName; 
                    lastName = assignee.lastName;  
                    }% 
                    ${firstName} ${lastName} 
                    %{ 
                    } 
                    else  
                    { 
                    }% <a href="@{Tasks.renderAssignLoggedToTask(projectTask.getEntityId(),project.getEntityId())}">Assign me !</a>
                    %{
                    }
                    }%
                </td>
                <td>
                    %{ 
                    reviewer = controllers.Tasks.renderGetTaskReviewer(projectTask.getEntityId());  
                    if(reviewer != null) 
                    {firstNameRev = reviewer.firstName; 
                    lastNameRev = reviewer.lastName;
                    }%
                    ${firstNameRev} ${lastNameRev}
                    %{
                    }
                    boolean hasRequested = controllers.Tasks.renderHasRequestedReview(projectTask.getEntityId());
                    if(hasRequested == true)
                    {
                    }%<i>pending reply</i>
                    %{
                    }
                    else
                    {
                    if(reviewer == null  && assignee != user)
                    {
                    }%
                    #{if controllers.Security.checkPermission(
                    "assign myself as a reviewer", project)}<a href="@{Tasks.renderReviewTask(projectTask.getEntityId())}">Review task</a>
                    #{/if} 
                    #{else} 
                    #{secure.check 'review a task'}<a href="@{Tasks.renderRequestReviewTask(projectTask.getEntityId())}">Request to review task</a>
                    #{/secure.check}
                    #{/else}
                    %{
                    }
                    }
                    }%
                </td>
            </tr>
            #{/list}
        </tbody>
        <tfoot>
            <tr>
                <th>
                    <input type="text" name="search_engine" value="Tasks" class="search_init" />
                </th>
                <th>
                    <input type="text" name="search_browser" value="Types" class="search_init" />
                </th>
                <th>
                    <input type="text" name="search_platform" value="Statuses" class="search_init" />
                </th>
                <th>
                    <input type="text" name="search_version" value="Priorities" class="search_init" />
                </th>
                <th>
                    <input type="text" name="search_grade" value="Creators" class="search_init" />
                </th>
                <th>
                    <input type="text" name="search_grade" value="Assignees" class="search_init" />
                </th>
                <th>
                    <input type="text" name="search_grade" value="Reviewers" class="search_init" />
                </th>
            </tr>
        </tfoot>
    </table>#{/if}
</body>
<script>
    $(function(){
        $(".link").tipTip();
    });
</script>
